<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html" 
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:c="http://java.sun.com/jsp/jstl/core">
    <body>

        <ui:composition template="./templates/basicTemplate.xhtml">
            <ui:define name="content">


                <p:panel header="#{ticket.ticket.title} - #{ticket.ticket.ticket_state}"> 
                    <f:facet name="footer">
                        <h:outputText value="#{ticket.ticket.created}">
                            <f:convertDateTime type="both" timeZone="CET" />
                        </h:outputText>                        
                    </f:facet>
                    <h:outputText value="#{ticket.ticket.content}" escape="false"/> 
                </p:panel> 

                <br/>

                <p:panelGrid style="width: 100%">
                    <f:facet name="header">  
                        <p:row>  
                            <p:column colspan="1">Komentáře</p:column>  
                            <p:column colspan="1" rendered="#{login.loggedSystemAdmin}">Nástroje</p:column> 
                            <p:column colspan="1" rendered="#{login.loggedSystemCustomer}">Informace o  řešení</p:column>
                        </p:row>  
                    </f:facet> 
                    <p:row>
                        <p:column>
                            <h:form id="new_post">
                                <p:accordionPanel var="item" value="#{ticket.posts}" multiple="true" activeIndex="0, 1, 2">
                                    <p:tab>
                                        <f:facet name="title">
                                            <h:outputText value="#{item.wroteBy.name} #{item.wroteBy.surname} [ "/>
                                            <h:outputText value="#{item.created}" style="font-size: 10pt;">
                                                <f:convertDateTime type="both" timeZone="CET" />
                                            </h:outputText> 
                                            <h:outputText value=" ]"/>
                                        </f:facet>

                                        <h:outputText value="#{item.content}" escape="false"/>
                                    </p:tab>
                                </p:accordionPanel>  
                                <br/>

                                <p:panelGrid columns="2" style="width:100%"> 
                                    <f:facet name="header">   
                                        <h:outputText value="Vložit komentář" />
                                    </f:facet>
                                    <h:outputLabel value="Váš text:" for="content" />
                                    <p:editor validatorMessage="Nelze odeslat prázdný komentář" controls="bold italic underline size color" id="content" value="#{newPostForm.content}">
                                        <f:validateRequired/>
                                    </p:editor>

                                    <f:facet name="footer">
                                        <p:commandButton value="Přidat komentář" action="#{newPostForm.savePost(ticket.ticket)}" update="new_post"/>
                                    </f:facet>
                                </p:panelGrid>
                            </h:form>
                        </p:column>
                        <p:column rendered="#{login.loggedSystemAdmin}"> 
                            <h:form id="takeTicket">
                                <p:panelGrid columns="1" style="width:100%; text-align: center;"> 
                                    <f:facet name="header">   
                                        <h:outputText value="Řešitel: " />                                      
                                    </f:facet> 
                                    <h:outputText value="#{ticket.ticket.solvedBy}" rendered="#{ticket.hasSolver()}"/>  
                                    <f:facet name="footer">
                                        <p:commandButton action="#{ticket.takeTicket(ticket.ticket)}" value="Ujmout se řešení" update="takeTicket"/>
                                        <p:commandButton action="#{ticket.dismissTicket(ticket.ticket)}" value="Odebrat řešitele" update="takeTicket" rendered="#{ticket.hasSolver()}"/>  
                                    </f:facet>

                                </p:panelGrid>
                            </h:form>
                            <br/>
                            <h:form id="ticketChange" >
                                <p:panelGrid columns="2" style="width:100%"> 

                                    <f:facet name="header">   
                                        <h:outputText value="Nastavit Cenu" />
                                    </f:facet> 

                                    <h:outputLabel value="Kolik (Kč):" for="price" />
                                    <p:spinner id="price" value="#{ticket.ticket.price}"/>
                                </p:panelGrid>
                                <br/>
                                <p:panelGrid columns="2" style="width:100%"> 
                                    <f:facet name="header">   
                                        <h:outputText value="Nastavit stav" />
                                    </f:facet> 
                                    <h:outputLabel value="Stav:" for="state" />
                                    <p:selectOneMenu value="#{ticket.ticket.ticket_state}" id="state">
                                        <f:selectItem itemLabel="Čeká" itemValue="0"/> 
                                        <f:selectItem itemLabel="V řešení" itemValue="1"/>
                                        <f:selectItem itemLabel="V řešení - Čeká na potvrzení ceny" itemValue="2"/>  
                                        <f:selectItem itemLabel="V řešení - Cena potvrzena" itemValue="3"/> 
                                        <f:selectItem itemLabel="Vyřešen" itemValue="4"/>
                                        <f:selectItem itemLabel="Zrušen" itemValue="5"/> 
                                        <f:selectItem itemLabel="Cena odmítnuta" itemValue="6"/> 
                                    </p:selectOneMenu>

                                    <f:facet name="footer">
                                        <p:commandButton value="Uložit" action="#{ticket.saveTicket(ticket.ticket)}" icon="ui-icon-check" update="ticketChange"/>
                                    </f:facet>
                                </p:panelGrid>
                            </h:form> 
                        </p:column>
                        <p:column rendered="#{login.loggedSystemCustomer}" style="min-width: 250px;">
                            <h:form id="ticinfo">
                                <p:panelGrid columns="1" style="width:100%; text-align: center"> 
                                    <f:facet name="header">   
                                        <h:outputText value="Stav ticketu" />
                                    </f:facet> 
                                    <h:outputLabel value="#{ticket.stringState(ticket.ticket)}"/>
                                </p:panelGrid>  
                                <br/>

                                <p:panelGrid columns="1" style="width:100%; text-align: center"> 
                                    <f:facet name="header">   
                                        <h:outputText value="Cena" />
                                    </f:facet> 
                                    <h:outputLabel value="#{ticket.ticket.price}"/>
                                    <f:facet name="footer">   
                                        <p:commandButton value="ANO" action="#{ticket.agree(ticket.ticket)}" update="ticinfo" rendered="#{ticket.waitingAgree()}"/>
                                        <p:commandButton value="NE" action="#{ticket.decline(ticket.ticket)}" update="ticinfo" rendered="#{ticket.waitingAgree()}"/>
                                    </f:facet>   
                                </p:panelGrid>
                            </h:form>   
                        </p:column>
                    </p:row>
                </p:panelGrid>
            </ui:define>
        </ui:composition>
    </body>
</html>
